# -*- coding: utf-8 -*-

import pymysql
import time

db = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="root", db="test", charset="utf8")


def mysql_checking(mobile_no):
    cursor = db.cursor()
    sql_demand = "SELECT 1 FROM 1688_all_spider WHERE mobile_no='" + mobile_no + "' LIMIT 1"
    demand = cursor.execute(sql_demand)
    db.commit()
    cursor.close()
    if demand > 0:
        print('联系方式已存在')
        return False
    else:
        return True


def mysql_memberid(mobile_no):
    cursor = db.cursor()
    sql_demand = "SELECT 1 FROM 1688_memberid WHERE memberid='" + mobile_no + "' LIMIT 1"
    demand = cursor.execute(sql_demand)
    db.commit()
    cursor.close()
    if demand > 0:
        print('memberid已存在',str(time.strftime('%Y-%m-%d %H:%M:%S')))
        return False
    else:
        return True


def insert_merberid(c, e,p):
    cursor = db.cursor()
    count = cursor.execute(
        "insert into 1688_memberid(id,name,addr,memberid,tf) value (NULL ,'%s','%s','%s',0)" % (c, e,p))
    db.commit()
    cursor.close()
